<%@page import="java.text.SimpleDateFormat"%>
<%@page import="common.DButil"%>
<%@page import="org.jfree.data.category.CategoryDataset"%>
<%@page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@page import="org.jfree.chart.plot.PlotOrientation"%>
<%@page import="org.jfree.chart.JFreeChart"%>
<%@page import="org.jfree.data.general.DatasetUtilities"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="org.jfree.chart.ChartFactory"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    
    <style type="text/css">
    	#i1{
    		position:absolute;
    	top:353.5px;
    	left:7px;
    	}
    	#i2{
    		position:absolute;
    	top:353.5px;
    	left:400px;
    	}
    	#i4{
    		position:absolute;
    	top:353.5px;
    	left:200px;
    	}
    	#i3{
    		position:absolute;
    	top:353.5px;
    	left:560px;
    	}
    	
    </style>
    <base href="<%=basePath%>">
    
    <title>My JSP 'zhuxingtu.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	

  </head>
  
  <body>
   <% 
 
   
  String[] s1=(String[])request.getAttribute("s1");
  String[] s2=(String[])request.getAttribute("s2");
  String[] s4=(String[])request.getAttribute("s4");
    
    if(s1 !=null){
    
   
   
   
   
   DButil db = DButil.getInstance();
		// 第一根柱子的数据
		String sqljc1="select count(out_time) from borrow where out_time>='"+s1[0]+"-"+s1[1]+"-"+s1[2]+"' AND out_time<'"+s1[0]+"-"+s1[1]+"-30'" ;
		List<String[]> jiechu1 = db.excuteQuery(sqljc1);
		String j=jiechu1.get(0)[0];
		int j1 = Integer.parseInt(j);
		
		String sqljc2="select count(out_time) from borrow where out_time>='"+s2[0]+"-"+s2[1]+"-"+s2[2]+"' AND out_time<'"+s2[0]+"-"+s2[1]+"-30'" ;
		List<String[]> jiechu2 = db.excuteQuery(sqljc2);
		String jj=jiechu2.get(0)[0];
		int j2 = Integer.parseInt(jj);
		
		String sqljc4="select count(out_time) from borrow where out_time>='"+s4[0]+"-"+s4[1]+"-"+s4[2]+"' AND out_time<'"+s4[0]+"-"+s4[1]+"-30'" ;
		List<String[]> jiechu4 = db.excuteQuery(sqljc4);
		String jjj=jiechu4.get(0)[0];
		int j4 = Integer.parseInt(jjj);
		
   double[][]data=new double[][]{{j1},{j2},{j4}};
   String[]rowKeys={""+s1[0]+"年"+""+s1[1]+"月的读者",""+s2[0]+"年"+""+s2[1]+"月的读者",""+s4[0]+"年"+""+s4[1]+"月的读者"};
   String[]columnKeys={""};
   CategoryDataset dataset= DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
   JFreeChart chart=ChartFactory.createBarChart3D("借出统计图","月份","数量",dataset,PlotOrientation.VERTICAL,true,false,false);
   String filename=ServletUtilities.saveChartAsJPEG(chart, 600, 400, null, session);
   String graphURL=request.getContextPath()+"/DisplayChart?filename="+filename;
   %>
   
   <form action="jsp/tx" method="post">
    <img  src="<%=graphURL%>"width="600" height="400" border="0" usemap="#<%=filename%>">
  
    <input  id="i1" name="p1" type="text" maxlength="10" onclick="new Calendar().show(this);" readonly value="2014-06-01" />
    <input id="i4" name="p4" type="text" maxlength="10" onclick="new Calendar().show(this);" readonly value="2014-07-01"/>
    <input id="i2" name="p2" type="text" maxlength="10" onclick="new Calendar().show(this);" readonly value="2014-08-01"/>
    <input id="i3" type="submit" value="确定" >
    </form>
    <% 
    }else{
   
   
  
   
   
   DButil db = DButil.getInstance();
		// 借出图书6月
		String sqljc6="select count(out_time) from borrow where out_time>='2014-01-01' AND out_time<'2014-01-30'" ;
		List<String[]> jiechu6 = db.excuteQuery(sqljc6);
		String j=jiechu6.get(0)[0];
		int j6 = Integer.parseInt(j);
		
   double[][]data=new double[][]{{j6}};
   String[] rowKeys={"没输入数据"};
   String[] columnKeys={""};
   CategoryDataset dataset= DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
   JFreeChart chart=ChartFactory.createBarChart3D("借出统计图","月份","数量",dataset,PlotOrientation.VERTICAL,true,false,false);
   String filename=ServletUtilities.saveChartAsJPEG(chart, 600, 400, null, session);
   String graphURL=request.getContextPath()+"/DisplayChart?filename="+filename;
    
    %>
    <form action="jsp/tx" method="post">
    <img  src="<%=graphURL%>"width="600" height="400" border="0" usemap="#<%=filename%>">
  
    <input  id="i1" name="p1" type="text" maxlength="10" onclick="new Calendar().show(this);" readonly value="2014-03-04" />
    
    <input id="i2" name="p2" type="text" maxlength="10" onclick="new Calendar().show(this);" readonly value="2014-05-09" />
    <input id="i4" name="p4" type="text" maxlength="10" onclick="new Calendar().show(this);" readonly value="2014-06-10" />
    <input id="i3" type="submit" value="确定" >
    </form>
   <h1>月份不能相等</h1> 
   <%} %> 
   
  </body>
      <script type="text/javascript" src="js\calendar.js"></script>
    <script type="text/javascript"></script>
</html>
